package com.gp.dal.typehandler;

import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import oracle.sql.CLOB;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

public class OracleClobTypeHandler implements TypeHandler<Object>{

	public Object getResult(ResultSet rs, String parameter) throws SQLException {
		Clob clob = rs.getClob(parameter);
		return (clob == null || clob.length() == 0) ? null : clob.getSubString((long) 1, (int) clob.length());
	}

	public Object getResult(ResultSet rs, int i) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public Object getResult(CallableStatement arg0, int i)
			throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public void setParameter(PreparedStatement ps, int i, Object parameter,
			JdbcType jdbcType) throws SQLException {
		CLOB clob = CLOB.empty_lob();
		clob.setString(1, (String) parameter);
		ps.setClob(i, clob);
	}

}
